var express = require('express');
var router = express.Router();
const {UserModel,WenjiModel}=require('../model/model')

/* GET home page. */
router.get('/getuser',async (req, res,)=>{
  let data=await UserModel.find()
  console.log(1);
  res.send({
    code:200,
    data
  })
});

router.get('/gettoken',(req,res)=>{
  let token='123'
  res.send({
    code:200,
    token
  })
})

router.get('/getwenji',async (req, res,)=>{
  let data=await WenjiModel.find()
  res.send({
    code:200,
    data
  })
})

router.get('/del',async (req, res,)=>{
  let {_id}=req.query
  await WenjiModel.deleteOne({_id})
  res.send({
    code:200
  })
})

router.post('/update',async(req,res)=>{
  let obj=req.body
  await WenjiModel.updateOne({_id:obj._id},{$set:obj})
  res.send({
    code:200
  })
})

router.post('/addwenji',(req,res)=>{
  let obj=req.body
  WenjiModel.create(obj)
  res.send({
    code:200
  })
})

module.exports = router;
